<template>
  <div>
    <van-cell-group inset v-for="(item, index) in detailsArr" :key="index" class="L-margin-top-20">
      <div class="L-form-title-row" @click="item.expand = !item.expand">
        <span class="L-text L-primary-text-color">
          <i class="iconfont icon-yuanzhu" style="color:#1683f7"></i>
          {{ item.grouptitle }}
        </span>
        <i class="iconfont" :class="item.expand ? 'icon-zhankai1' : 'icon-xiayibu2'"></i>
      </div>
      <van-cell-group v-show="item.expand">
        <template v-for="(fitem, findex) in item.groupvalue" :key="findex">
          <FormInput v-if="route.query.actiontype === 'mytask' && route.query.actioncode === 'unhandle'"
            :formItem="fitem" disableControlField="sEditable" @handleChange="handleChange" tableType="head"></FormInput>
          <DetailItem v-else :detailItem="fitem"></DetailItem>
        </template>
      </van-cell-group>
    </van-cell-group>

    <!-- Tabs -->
    <van-cell-group v-if="relevant.length > 0" inset class="L-margin-top-20" style="padding-bottom: 10px;">
      <van-tabs v-model:active="currentTab" class="L-margin-top-10">
        <van-tab v-for="(item, index) in relevant" :key="index" :title="item.title"
          :name="item.current_object"></van-tab>
      </van-tabs>

      <!-- 列表 -->
      <div class="L-base-list">
        <van-empty v-if="loading === false && list.length === 0" description="没有数据" />
        <!-- 骨架屏 -->
        <div v-if="loading">
          <van-skeleton title :row="3" v-for="item in 5" :key="item" style="margin-bottom:30px" />
        </div>

        <!-- 列表 -->
        <!-- <van-list v-else v-model:loading="loading" :finished="finished" :finished-text="list.length>0 ? '没有更多了':''" @load="onLoad"> -->
        <van-list v-else v-model:loading="loading" :finished="finished" :finished-text="list.length > 0 ? '没有更多了' : ''">

          <div class="base-item" v-for="(item, index) in list" :key="index">
            <van-row type="flex" align="center" @click="handleClick(item)">
              <van-col :span="23">
                <div class="L-text L-bold" v-html="item.title"></div>
                <div v-if="item.value">
                  <span class="L-secondary-text-color L-small-text" v-html="item.value"></span>
                </div>
                <template v-if="item.label">
                  <div class="L-secondary-text-color L-small-text" v-html="item.label"></div>
                </template>
              </van-col>
              <van-col :span="1">
                <i class="iconfont icon-jiufuqianbaoicon07"></i>
              </van-col>
            </van-row>
          </div>
        </van-list>
      </div>
    </van-cell-group>
    <!-- 历史操作 -->
    <van-cell-group inset class="L-margin-top-20" style="padding-bottom: 10px;">
      <div class="L-form-title-row">
        <span class="L-text L-primary-text-color">
          <!-- <i class="iconfont icon-gengxin1" ></i> -->
          历史操作
        </span>
        <!-- <i class="iconfont" :class="item.expand ? 'icon-zhankai1' :'icon-xiayibu2'"></i> -->
      </div>
      <TimeLine style="margin-top:30px" :alldata="history"></TimeLine>
    </van-cell-group>

    <!-- 按钮 -->
    <div class="L-bottom-space"></div>
    <van-sticky position="bottom">
      <div class="L-bottom-row">
        <van-row gutter="10" style="width: 100%;text-align: center;">
          <template v-if="isowner === '1' && route.query.actioncode === 'unhandle'">

            <van-col :span="6">
              <van-button color="#e5ebfa" type="primary" size="small" style="width:80%;color:#3677f6"
                @click="handleClickOperate('agree')">同意</van-button>
            </van-col>
            <van-col :span="6">
              <van-button color="#e5ebfa" type="primary" size="small" style="width:80%;color:#3677f6"
                @click="handleClickOperate('turndone')">转办</van-button>
            </van-col>
            <van-col :span="6">
              <van-button color="#e5ebfa" type="primary" size="small" style="width:80%;color:#3677f6"
                @click="handleClickOperate('sendback')">退回</van-button>
            </van-col>
            <van-col :span="6">
              <van-button color="#e5ebfa" type="primary" size="small" style="width:80%;color:#3677f6"
                @click="handleClickOperate('veto')">否决</van-button>
            </van-col>
          </template>

          <van-col :span="24" v-show="route.query.actiontype === 'mysend' && route.query.actioncode === 'unhandle'">
            <van-button @click="handleSubmit" type="primary" style="width:90%;">提交</van-button>
          </van-col>

          <van-col :span="24"
            v-show="(route.query.actiontype === 'mytask' || route.query.actiontype === 'mysend') && route.query.actioncode === 'handle'">
            <van-button @click="handleBack" type="primary" style="width:90%;">取回</van-button>
          </van-col>
        </van-row>

      </div>
    </van-sticky>

    <!-- Tab详情弹窗 -->
    <van-popup v-model:show="showDetailPopup" position="bottom" style="width: 100%;height:90vh" round>
      <van-cell-group inset v-for="(item, index) in tabDetailsArr" :key="index" class="L-margin-top-20">
        <div class="L-form-title-row" @click="item.expand = !item.expand">
          <span class="L-text L-primary-text-color">
            <i class="iconfont icon-yuanzhu" style="color:#1683f7"></i>
            {{ item.title }}
          </span>
          <i class="iconfont" :class="item.expand ? 'icon-zhankai1' : 'icon-xiayibu2'"></i>
        </div>
        <van-cell-group v-show="item.expand">
          <template v-for="(fitem, findex) in item.groupvalue" :key="findex">

            <FormInput
              v-if="route.query.actiontype === 'mytask' && route.query.actioncode === 'unhandle' && currentTab === bodyObject"
              :formItem="fitem" disableControlField="sEditable" @handleChange="handleChange" tableType="head">
            </FormInput>

            <DetailItem v-else :detailItem="fitem"></DetailItem>






          </template>
          <template
            v-if="route.query.actiontype === 'mytask' && route.query.actioncode === 'unhandle' && currentTab === bodyObject">

            <div class="L-bottom-space"></div>
            <van-sticky position="bottom">
              <div class="L-bottom-row">
                <div class="L-operate-btn" @click="showDetailPopup = false">取消</div>
                <div class="L-operate-btn" @click="handleBodySave">保存</div>

              </div>
            </van-sticky>
          </template>
        </van-cell-group>
      </van-cell-group>

    </van-popup>

    <!-- 同意弹窗 -->
    <van-popup v-model:show="showAgreePopup" position="bottom" class="L-popup-container" :lock-scroll="false"
      :overlay="false">

      <div class="L-optionBox">

        <div class="L-optionBox-title">
          <div>审批意见</div>
          <div style="text-align:right"><i class="iconfont icon-shanchu6" @click="showAgreePopup = false"></i></div>
        </div>
        <div class="messageBox">
          <van-field maxlength="100" style="border-radius:6px" show-word-limit v-model="opinionText" rows="2" autosize
            type="textarea" placeholder="请输入意见" />
        </div>
        <div v-if="currentOperation === 'agree'">
          <van-uploader :preview-image="false" placeholder="请选择文件" v-model="uploadList" :after-read="handleUpload"
            accept="*" multiple>
            <van-button plain block style="width: 90vw;margin-left:2vw" icon="back-top" type="primary">上传附件</van-button>
          </van-uploader>
        </div>
        <div class="L-fileBox" v-if="currentOperation === 'agree'">
          <div class="L-fileBox-item" v-for="item in uploadList" :key="item.newname">
            <i class="el-icon-link"></i>
            {{ item.oldname }}
          </div>
        </div>
        <div class="L-bottom-row" style="background: none;">
          <van-button style="width: 90%;" round block type="primary" @click="handleAgree">提交</van-button>
        </div>

      </div>
    </van-popup>
    <!-- 退回弹窗 -->
    <van-popup style="height:250px" v-model:show="showSendBackPopup" position="bottom" class="L-popup-container"
      :lock-scroll="false" :overlay="false">

      <div class="L-optionBox">

        <div class="L-optionBox-title">
          <div>审批意见</div>
          <div style="text-align:right"><i class="iconfont icon-shanchu6" @click="showSendBackPopup = false"></i></div>
        </div>
        <div class="messageBox">
          <van-field maxlength="100" style="border-radius:6px" show-word-limit v-model="opinionText" rows="2" autosize
            type="textarea" placeholder="请输入意见" />
        </div>

        <div class="L-bottom-row" style="background: none;">
          <van-button style="width: 90%;" round block type="primary" @click="handleSendBack">提交</van-button>
        </div>

      </div>
    </van-popup>

    <!-- 否决弹窗 -->
    <van-popup style="height:250px" v-model:show="showVetoPopup" position="bottom" class="L-popup-container"
      :lock-scroll="false" :overlay="false">

      <div class="L-optionBox">

        <div class="L-optionBox-title">
          <div>审批意见</div>
          <div style="text-align:right"><i class="iconfont icon-shanchu6" @click="showVetoPopup = false"></i></div>
        </div>
        <div class="messageBox">
          <van-field maxlength="100" style="border-radius:6px" show-word-limit v-model="opinionText" rows="2" autosize
            type="textarea" placeholder="请输入意见" />
        </div>

        <div class="L-bottom-row" style="background: none;">
          <van-button style="width: 90%;" round block type="primary" @click="handleVetoBack">提交</van-button>
        </div>

      </div>
    </van-popup>

    <!-- 转办弹窗 -->
    <van-popup style="height:300px;padding-top:20px" v-model:show="showTurnDonePopup" class="L-popup-container"
      position="bottom" :lock-scroll="false" :overlay="false">
      <!-- <div class="L-text-align-center">转办</div> -->
      <div style="width:90%;display: flex;margin:0px auto;justify-content: space-between;">
        <div>转办</div>
        <div style="text-align:right"><i class="iconfont icon-shanchu6" @click="showTurnDonePopup = false"></i></div>
      </div>
      <div class="L-optionBox" style="margin-top:20px">
        <FormInput :formItem="clrFormObj" @handleChange="handleChange" tableType="head"></FormInput>
        <van-field v-model="opinionText" rows="2" label="审批意见" type="textarea" maxlength="1000" placeholder="请输入审批意见"
          show-word-limit />
        <div class="L-bottom-row" style="background: none;">
          <van-button style="width: 90%;" round block type="primary" @click="handleTurnDone">提交</van-button>
        </div>
      </div>
    </van-popup>

  </div>
</template>

<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
import {
  closeToast,
  showLoadingToast,
  showSuccessToast,
  showConfirmDialog,
  showToast,
} from "vant";
import DetailItem from "@/components/base/Detail/DetailItem.vue";
import TimeLine from "@/components/base/Flow/TimeLine.vue";
import FormInput from "@/components/base/Form/FormInput.vue";
import OrgRef from "@/components/base//Ref/OrgRef.vue";

import { apiConfigurable, apiUploadFile } from "@/request/api/api";
import { useRoute, useRouter } from "vue-router";

const router = useRouter();
const route = useRoute();

onMounted(() => {
  getData();
});

const headinfo = ref({});
const operation = ref([]);
const detailsArr = ref([]);
const relevant = ref([]);
const loading = ref(false);
const currentTab = ref("");
const history = ref([]);
const isowner = ref("");
import type { flowCardJsonDataVO } from "@/interface/interface"
const jsondata = ref<flowCardJsonDataVO>({});
const orginData = ref({});

const opinionText = ref("");

interface params {
  [idx: string]: any;
}
function getData() {
  const { idobject, idbill, idflow } = route.query;
  const params: params = {};
  params[`idobject`] = idobject;
  params[`idbill`] = idbill;
  params[`idflow`] = idflow;

  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });
  loading.value = true;
  // const url = `flowclmx.check.do`;

  const url = route.query.actiontype === 'mytask' && route.query.actioncode === 'handle' ? '/api/flowrecord.check.do' : '/api/flowclmx.check.do';

  apiConfigurable(url, params).then(async (res) => {
    // const jsondata = res.data.jsondata;
    jsondata.value = res.data.jsondata;

    //字段联动
    orginData.value = JSON.parse(JSON.stringify(res.data.jsondata));
    controlLinkArr.value = getFieldLink(jsondata.value);

    detailsArr.value = jsondata.value.head.map((item) => {
      return { expand: true, ...item };
    });

    history.value = jsondata.value.history;

    relevant.value = jsondata.value.relevant;

    currentTab.value = relevant.value.length > 0 ? relevant.value[0].current_object : "";

    isowner.value = jsondata.value.isowner || "";

    loading.value = false;

    closeToast();
  });
}
const bodyObject = computed(() => {
  return relevant.value.find(item => {
    return item.isbody
  })?.current_object || ""
})

const activeTab = ref("");
function handleChangeTab(value) {
  activeTab.value = value;
}

// 列表
const list = ref([]);
const startline = ref(1);
const pagecount = ref(20); //每页条数
const finished = ref(false); //列表是否加载完成

//初始化查询条件
function initCondition() {
  startline.value = 1;
  finished.value = false;
  list.value = [];
}

watch(currentTab, (value) => {
  relevant.value.forEach((item, index) => {
    if (item.current_object === value) {
      initCondition();
      onLoad(item);
    }
  });
});

function onLoad(item) {
  let params = {
    startline: startline.value,
    pagecount: pagecount.value,
  };
  const data = {
    ...params,
    relvalue: route.query.idbill,
    relfield: item.relfield,
  };
  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });
  const url = `${item.current_object}.list.do`;

  loading.value = true;
  apiConfigurable(url, data).then((res) => {
    if (res.code === 0) {
      if (res.data?.jsondata?.fieldValue.length < pagecount.value) {
        finished.value = true;
      }
      list.value = [...list.value, ...res.data?.jsondata?.fieldValue];
      startline.value = list.value.length + 1;
      loading.value = false;
      closeToast();
    }
  }).finally(() => {
    loading.value = false;
  });
}


function handleClick(item) {

  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });

  const isbody = bodyObject.value === currentTab.value


  const url = isbody ? `${currentTab.value}.edit.do` : `${currentTab.value}.check.do`;
  const params = {
    [`${currentTab.value}_id`]: item.id,
  };
  currentDetailId.value = item.id
  apiConfigurable(url, params).then(async (res) => {
    if (res.code === 0) {
      if (isbody) {
        // 子表
        const jsondata = res.data.jsondata;
        tabDetailsArr.value = jsondata.head.map((item) => {
          return { expand: true, ...item, title: item.grouptitle };
        });

      } else {
        // 非子表
        const jsondata = res.data.jsondata;
        tabDetailsArr.value = jsondata.Details.map((item) => {
          return { expand: true, ...item, title: item.groupStitle };
        });

      }
    }

    showDetailPopup.value = true;

    closeToast();
  });
}
interface tabDetailsItemVO {
  head?: string,
  [key: string]: any
}

const tabDetailsArr = ref<tabDetailsItemVO[]>([]);
const currentDetailId = ref("")
const showDetailPopup = ref(false);
const currentOperation = ref("");

const uploadList = ref([]);

const showAgreePopup = ref(false);
const showTurnDonePopup = ref(false);
const showSendBackPopup = ref(false);
const showVetoPopup = ref(false);

function handleClickOperate(operateName: string) {
  currentOperation.value = operateName;
  switch (operateName) {
    case "agree":
      showAgreePopup.value = true;
      break;
    case "turndone":
      showTurnDonePopup.value = true;
      break;
    case "sendback":
      showSendBackPopup.value = true;
      break;
    case "veto":
      showVetoPopup.value = true;
      break;
  }
}

// 上传
function handleUpload(file, detail) {
  let deviceFile = [];
  let formData = new FormData();
  if (Array.isArray(file)) {
    deviceFile = file;
  } else {
    deviceFile.push(file);
  }
  for (let i = 0; i < deviceFile.length; i++) {
    formData.append("file" + i, deviceFile[i].file, deviceFile[i].name);
  }

  apiUploadFile(formData).then((res) => {
    if (res.code === 0) {
      let fileInfo = res.data;
      const newnameList = fileInfo[0].newname.split(";");
      const oldnameList = fileInfo[0].oldname.split(";");
      const fileList = newnameList.map((item, index) => {
        const file = { newname: item, oldname: oldnameList[index] };
        return file;
      });

      uploadList.value = [...uploadList.value, ...fileList];

      // for (let headIdx = 0; headIdx < jsondata.value.head.length; headIdx++) {
      //   let headData = jsondata.value.head[headIdx].groupvalue;
      //   for (let i = 0; i < headData.length; i++) {
      //     if (headData[i].sField === detail.name) {
      //       headData[i].valuehidden = fileInfo[0].newname;
      //       headData[i].value = fileInfo[0].oldname;
      //     }
      //   }
      // }
      showToast("上传成功");
    } else {
      showToast("上传失败");
    }
  });
}

function handleOptionSubmit() { }

// interface submitData {
//   [name: string]: any;
// }
function handleBodySave() {
  const idobject = currentTab.value
  const data = {};
  data[idobject + "_id"] = currentDetailId.value




  for (let i=0;i<tabDetailsArr.value[0].groupvalue.length;i++) {
    let itemdata = tabDetailsArr.value[0].groupvalue[i];
    if (!checkForm(itemdata)) {
      return;
    }
    if (itemdata.sUIType === "ref") {
      data[itemdata.idObject + "_" + itemdata.sField] = itemdata.valuehidden;
      data[itemdata.idObject + "_" + itemdata.sField + "_ref"] = itemdata.value;
    } else if (itemdata.sUIType === "enum") {
      data[itemdata.idObject + "_" + itemdata.sField] = itemdata.valuehidden;
      data[itemdata.idObject + "_" + itemdata.sField + "_enum"] = itemdata.value;
    } else if (
      itemdata.sUIType === "file" ||
      itemdata.sUIType === "picture"
    ) {
      data[itemdata.idObject + "_" + itemdata.sField] = itemdata.valuehidden;
      data[itemdata.idObject + "_" + itemdata.sField + "_title"] = itemdata.value;
    } else {
      data[itemdata.idObject + "_" + itemdata.sField] = itemdata.value;
    }
  }



  showLoadingToast({
    message: "保存中...",
    forbidClick: true,
    duration: 0,
  });
  const api = `${idobject}.editsave.do`

  apiConfigurable(api, data).then(async (res) => {
    if (res.code === 0) {

      showSuccessToast("已保存");


      setTimeout(() => {
        closeToast();
        showDetailPopup.value = false

      }, 1000)

    }
  });

}

//字段联动hooks
import { useFieldLinkage } from "@/hooks/hooks.js";
const { controlLinkArr, getFieldLink, handleFiledLink, flLogicalJudgment } =
  useFieldLinkage();
//字段映射hooks
import { useFieldMap } from "@/hooks/hooks.js";
const { handleFiledMap } = useFieldMap();

// 字段值发生变化
function handleChange(
  item,
  value,
  valuehidden = "",
  fieldmap = {},
  mapobject = "",
  tableType = "head",
  bodyDataName = "",
  bodyDataIndex = ""
) {
  item.value = value;
  if (valuehidden) {
    item.valuehidden = valuehidden;
  }

  return;

  //字段联动
  handleFiledLink(item, jsondata.value, orginData.value);

  //字段映射(和插入点)
  if (fieldmap && mapobject) {
    handleFiledMap(
      jsondata,
      fieldmap,
      mapobject,
      tableType,
      bodyDataName,
      bodyDataIndex
    );
  }
}

interface submitData {
  [name: string]: any;
}
function checkForm(itemdata) {
  if (itemdata.lMustInput === "1" && itemdata.value === "") {
    showToast(`${itemdata.sTitle}不能为空`);
    return false;
  }
  return true;
}

// 同意
function handleAgree() {
  const data: submitData = {};
  const { idobject, idflow, idbill, idtemplate } = route.query;
  let filename = "";
  let filetitle = "";

  if (uploadList.value.length > 0) {
    uploadList.value.forEach((item, index) => {
      if (index < uploadList.value.length - 1) {
        filename += item.newname + ";";
        filetitle += item.oldname + ";";
      } else {
        filename += item.newname;
        filetitle += item.oldname;
      }
    });
  }
  data["opinion"] = opinionText.value;
  data["batchoperation"] = idflow;
  data["bo"] = idobject;
  data["filename"] = filename;
  data["filetitle"] = filetitle;

  // data = {
  //   opinion: this.opinion,
  //   batchoperation: this.idflow + ";",
  //   bo: this.idobject,
  //   filename,
  //   filetitle,
  // };

  data[idobject + "_id"] = idbill;
  data[idobject + "_idtemplate"] = idtemplate;

  for (let groupindex in jsondata.value.head) {
    let itemgroup = jsondata.value.head[groupindex].groupvalue;
    for (let itemindex in itemgroup) {
      let itemdata = itemgroup[itemindex];
      if (!checkForm(itemdata)) {
        return;
      }
      if (itemdata.sUIType === "ref") {
        data[itemdata.idObject + "_" + itemdata.sField] = itemdata.valuehidden;
        data[itemdata.idObject + "_" + itemdata.sField + "_ref"] = itemdata.value;
      } else if (itemdata.sUIType === "enum") {
        data[itemdata.idObject + "_" + itemdata.sField] = itemdata.valuehidden;
        data[itemdata.idObject + "_" + itemdata.sField + "_enum"] = itemdata.value;
      } else if (
        itemdata.sUIType === "file" ||
        itemdata.sUIType === "picture"
      ) {
        data[itemdata.idObject + "_" + itemdata.sField] = itemdata.valuehidden;
        data[itemdata.idObject + "_" + itemdata.sField + "_title"] = itemdata.value;
      } else {
        data[itemdata.idObject + "_" + itemdata.sField] = itemdata.value;
      }
    }
  }

  if (jsondata.value.hasdetail === "1") {
    for (let indexName in jsondata.value.bodydata) {
      for (let i = 0; i < jsondata.value.bodydata[indexName].length; i++) {
        let item = jsondata.value.bodydata[indexName][i];
        for (let itemindex in item) {
          let itemdata = item[itemindex];
          if (itemdata.sUIType === "ref") {
            data[i + "_" + itemdata.idObject + "_" + itemdata.sField] =
              itemdata.valuehidden;
            data[i + "_" + itemdata.idObject + "_" + itemdata.sField + "_ref"] =
              itemdata.value;
          } else if (itemdata.sUIType === "enum") {
            data[i + "_" + itemdata.idObject + "_" + itemdata.sField] =
              itemdata.valuehidden;
            data[
              i + "_" + itemdata.idObject + "_" + itemdata.sField + "_enum"
            ] = itemdata.value;
          } else {
            data[i + "_" + itemdata.idObject + "_" + itemdata.sField] =
              itemdata.value;
          }
        }
      }
    }
  }

  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });

  apiConfigurable("flowclmx.agree.do", data, "post").then((res) => {
    if (res.code === 0) {
      showSuccessToast("操作成功!");
      setTimeout(() => {
        router.go(-1);
        closeToast();
      }, 2000);
    }
  });
}
// 退回
function handleSendBack() {
  const data: submitData = {};
  const { idflow } = route.query;
  data["opinion"] = opinionText.value;
  data["batchoperation"] = idflow;

  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });

  apiConfigurable("flowclmx.batsendback.do", data, "post").then((res) => {
    if (res.code === 0) {
      showSuccessToast("操作成功!");
      // showSendBackPopup.value = false;
      setTimeout(() => {
        closeToast();
        router.go(-1);
      }, 2000);
    }
  });
}
// 否决
function handleVetoBack() {
  const data: submitData = {};
  const { idflow, idobject } = route.query;
  data["opinion"] = opinionText.value;
  data["idflow"] = idflow;
  data["idobject"] = idobject;

  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });

  apiConfigurable("flowclmx.veto.do", data, "post").then((res) => {
    if (res.code === 0) {
      showSuccessToast("操作成功!");

      setTimeout(() => {
        router.go(-1);
        closeToast();
      }, 2000);
    }
  });
}

// 提交
function handleSubmit() {
  const data: submitData = {};
  const { idflow, idobject, idbill } = route.query;
  data["id"] = idbill;
  data["idflow"] = idflow;
  data["idobject"] = idobject;

  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });

  apiConfigurable("flowclmx.submit.do", data, "post").then((res) => {
    if (res.code === 0) {
      showSuccessToast("操作成功!");

      setTimeout(() => {
        router.go(-1);
        closeToast();
      }, 2000);
    }
  });
}

// 取回
function handleBack() {
  const data: submitData = {};
  const { idflow, idobject, idbill } = route.query;
  data["id"] = idbill;
  data["idflow"] = idflow;
  data["idobject"] = idobject;

  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });

  apiConfigurable("flowclmx.back.do", data, "post").then((res) => {
    if (res.code === 0) {
      showSuccessToast("操作成功!");

      setTimeout(() => {
        router.go(-1);
        closeToast();
      }, 2000);
    }
  });
}

// 转办
const clrFormObj = ref({
  sRefKey: "13002637001710527179865071935319",
  idJoinObject: "employee",
  sUIType: "ref",
  idObject: "flowclmx",
  sField: "clr",
  lCanInput: "1",
  value: "",
  valuehidden: "",
  lMustInput: "1",
  sTitle: "处理人",
  sFieldRef: "sname",
  lCanOutput: "1",
});

function handleTurnDone() {

  if (clrFormObj.value.valuehidden === '') {
    showToast("请选择处理人")
    return
  }
  const data: submitData = {};
  const { idflow, idobject, idbill } = route.query;
  data["idbill"] = idbill;
  data["batchoperation"] = idflow;
  data["idobject"] = idobject;
  data["clrid"] = clrFormObj.value.valuehidden;
  data["clr"] = clrFormObj.value.value;
  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });

  apiConfigurable("flowclmx.turndone.do", data, "post").then((res) => {
    if (res.code === 0) {
      showSuccessToast("操作成功!");
      setTimeout(() => {
        router.go(-1);
        closeToast();
      }, 2000);
    }
  });
}

interface refParamsIF {
  id: string;
  title: string;
  address?: string;
  fieldmap?: object;
  mapobject?: string;
}
</script>

<style scoped>
.L-file-lable {
  color: #7e7878;
  font-size: 16px;
  line-height: 24px;
  padding: 10px 16px;
}

.L-popup-container {
  width: 100vw;
  height: 450px;
  border-top: 1px solid #f4f4f4;
  background: #fafafa;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 999;
}

.L-optionBox {
  /* box-sizing: border-box; */
  width: 100%;
  padding: 10px;
  box-sizing: border-box;
}

.L-optionBox .L-optionBox-title {
  width: 95%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px auto;
}

.L-optionBox .messageBox {
  width: 95%;
  border-radius: 10px;
  border: 1px solid #eee;
  padding: 10px;
  margin: 10px auto;
  background: #fff;
}

.L-optionBox .L-upload-btn {
  width: 90vw;
  margin: 10px auto;
}

.L-optionBox .L-fileBox {
  width: 95%;
  margin: 10px auto;
  height: 100px;
  overflow: auto;
}

.L-optionBox .L-fileBox .L-fileBox-item {
  font-size: 14px;
  /* color:#287dd6; */
  color: #606266;
  margin: 5px auto;
}

.fieldgroup_title {
  text-align: left;
  margin: 0px;
  padding: 25px 15px 15px;
  color: rgba(69, 90, 100, 0.6);
  font-weight: normal;
  font-size: 14px;
}

.valueleft {
  min-width: 70%;
  white-space: pre-wrap;
  display: inline-block;
  text-align: left;
  word-break: break-all;
}

.cellvalue1 .van-cell__value {
  position: relative;
  overflow: hidden;
  color: #323233;
  text-align: left;
  vertical-align: middle;
  word-wrap: break-word;
  flex: 2;
}

.cellvalue1 .van-cell__title {
  color: #999;
}
</style>
